﻿using Domain.Entitys;
using Domain.Repositorys;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repositorys
{
    public class SSDRepositoy : ISSDDRepositoy
    {
        private readonly MyDbContext myDbContext;

        public SSDRepositoy(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<List<SSD>> SSDselectAsync(int pageIndex, int pageSize)
        {
          return await myDbContext.SSD.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();
        }
        /// <summary>
        /// 薪酬标准单详细信息删除
        /// </summary>
        /// <param name="sSD"></param>
        /// <returns></returns>
        public async Task<int> SSDdelectAsync(SSD sSD)
        {
            myDbContext.SSD.Remove(sSD);
            return await  myDbContext.SaveChangesAsync();
        }

        /// <summary>
        /// 总数
        /// </summary>
        /// <returns></returns>
        public int SSDSelectCount()
        {
            return myDbContext.SSD.Count();
        }
        /// <summary>
        /// 薪酬标准单详细信添加
        /// </summary>
        /// <param name="sSD"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task< int> SSDAddAsync(List<SSD> sSDs)
        {
            //myDbContext.SSD.AddAsync(sSDs);
            //循环添加薪酬标准单详细信息
            foreach (SSD sSD in sSDs)
            {
                myDbContext.SSD.Add(sSD);
            }
            return   await myDbContext.SaveChangesAsync();
        }

        /// <summary>
        /// 查询全部薪酬数据
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<List<SSD>> SSDFileAsync()
        {
            return await myDbContext.SSD.ToListAsync();
        }

        /// <summary>
        /// 根据薪酬编号查询数据
        /// </summary>
        /// <param name="sid"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<List<SSD>> SSDSelectBySid(string sid)
        {
            return await myDbContext.SSD.Where(s => s.StandardId == sid).ToListAsync();
        }

        /// <summary>
        /// 修改薪酬标准数据
        /// </summary>
        /// <param name="sSDs"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> SSDUpdateAsync(List<SSD> sSDs)
        {
            foreach (var item in sSDs)
            {
                myDbContext.SSD.Update(item);
            }
            return await myDbContext.SaveChangesAsync();
        }
    }
}
